<?php
class Admin_Model_PageMapper {
	
	protected $_dbTable;
	
	public function setDbTable($dbTable) {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function getDbTable() {
        if (null === $this->_dbTable) {
            $this->setDbTable('Admin_Model_DbTable_Page');
        }
        
        return $this->_dbTable;
    }
    
	public function fetchAll($query) {
		$entries = array();
		
		if ($query === NULL) {
			$resultSet = $this->getDbTable()->fetchAll()->toArray();
		} else {
			$table = $this->getDbTable();
			$select = $table->select();
			$select->from($table)->where($query);
			$resultSet = $this->getDbTable()->fetchAll($select)->toArray();
		}
		
		foreach ($resultSet as $row) {
			$entry = new Admin_Model_TableColumn_Page($row);
			$entries[] = $entry;
		}
		
		return $entries;
	}

}
?>